package com.autoEcole.service;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

import com.autoEcole.dao.ExamenDAO;
import com.autoEcole.exception.ApplicationException;
import com.autoEcole.exception.DAOException;
import com.autoEcole.model.Examen;

public class ExamenService {
	
	private ExamenDAO examenDAO;
	/**
	 * ExamenService
	 */
	private static ExamenService examenService;
	
	/**
	 * Constructor
	 */
	private ExamenService() {
		super();
	}

	/**
	 * Returns the ExamenService instance (Design Pattern : Singleton)
	 * 
	 * @return ExamenService
	 */
	public static synchronized ExamenService getInstance() {
		if (examenService == null)
			examenService = new ExamenService();
		return examenService;
	}

	public ExamenDAO getExamenDAO() {
		return examenDAO;
	}

	public void setExamenDAO(ExamenDAO examenDAO) {
		this.examenDAO = examenDAO;
	}

	public int create(Examen examen) throws ApplicationException {
		try {
			return examenDAO.create(examen);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}

	/**
	 * 
	 */
	public void update(Examen examen) throws ApplicationException {
		try {
			examenDAO.update(examen);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}

	/**
	 * retourne l'element si il existe ou null
	 */
	public Examen findById(int id) throws ApplicationException {
		try {
			return examenDAO.findById(id);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}

	/**
	 * @throws ParseException 
	 * 
	 */
	public List<Examen> findAll() throws ApplicationException, ParseException {
		try {
			return examenDAO.findAll();
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}		
	}
	
	/**
	 * 
	 */
	public Map<Integer , Examen> findAllMap() throws ApplicationException {
		try {
			return examenDAO.findAllMap();
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}
	}
	
	/**
	 * 
	 */	
	public void delete(int examenId) throws ApplicationException {
		try {
			examenDAO.delete(examenId);
		} catch (DAOException ex) {
			throw new ApplicationException(ex);
		}		
	}	
}
